package com.zgkxzx.算法.斐波那契数列;

/**
 * 创建者   zgkxzx
 * 创建日期 2018/3/8.
 * 功能描述
 */

public class Fibonacci {

    public static int calc1(int num) {
        if (num == 0 || num == 1)
            return 1;
        else
            return calc1(num - 1) + calc1(num - 2);
    }

    public static int calc2(int num) {
        int last1Num = 1;
        int last2Num = 1;
        int currentNum = 1;
        for (int i = 2; i <= num; i++) {
            currentNum = last1Num + last2Num;
            last2Num = last1Num;
            last1Num = currentNum;

        }
        return currentNum;

    }
}
